<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : expanded2xhtml.xsl
    Created on : March 14, 2005, 3:22 PM
    Author     : alex
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
   xmlns:ex="http://www.infoset.org/Vocabulary/SchemaExpander/2008/1/0"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:h="http://www.w3.org/1999/xhtml"
   xmlns="http://www.w3.org/1999/xhtml"
   exclude-result-prefixes="ex xs h"
   >
   
<xsl:import href="schema2xhtml.xsl"/>

<xsl:output method="xml"
            cdata-section-elements="script"/>

<xsl:variable name="prefixes" select="/ex:expanded-schema/ex:prefixes[1]"/>

<xsl:param name="title">Schema Documentation</xsl:param>

<xsl:template name="generate-style">
<style type="text/css">
#ns-navigation {
   border-bottom: 0.5pt solid black;
   margin-bottom: 1em;
}

#current-ns {
   margin: 0pt;
   min-width: 50%;
   padding: 0.2em;
   font-family: monospace;
   font-size: 2.5em;
   font-eight: bold;
}

#ns-select {
   margin: 0pt;
   padding: 0.2em;
}

#schema {
   height: 100%;
}

.namespace {
   height: 100%;
}

.namespace-navigation {
   float: left;
   font-size: 75%;
   width: 20%;
   padding-left: 0.5em;
   padding-right: 0.5em;
   height: 100%;
}

.namespace-navigation ul li {
   margin: 0pt;
   padding: 0pt;
   margin-bottom: 0.1em;
}

.namespace-navigation p {
   margin: 0pt;
   padding: 0pt;
}

.namespace .contents {
   width: 78%;
   float: left;
}

.element, .type, .attribute {
   margin-bottom: 2em;
   border-bottom: 1px solid rgb(200,200,200);
}


p.link-title {
   font-size: 14pt;
   font-weight: bold;
}

p.link-title a {
   text-decoration: none;
   border: 1pt solid gray;
   padding: 3pt;
   margin-right: 3pt;
}

p.link-title a:hover {
   color: red;
}
p.link-title a:link, p.link-title a:visited {
   text-decoration: none;
}
p.title {
   padding: 3pt;
   font-weight: bold;
   font-size: 14pt;
}
div.items {
   padding-top: 5pt;
   padding-left: 10pt;
}
div.items p {
   padding: 0pt;
   margin: 0pt;
}

p.kind-title {
  font-size: 18pt;
  border-bottom: 1pt solid gray;
  font-weight: bold;
}

p.individual-title {

   padding-left: 15pt;
   font-size: 16pt;
}

table.namespace tr {
   vertical-align: top;
}

table.namespace {
   width: 7in;
}

table.namespace tr td {
   width: 1.75in;
   border-left: 1pt solid gray;
   padding: 5pt;
}

p.namespace {
   font-weight: bold;
   font-size: 120%;
}

div.documentation {
   border: 1pt solid gray;
   padding: 10pt;
   width: 7.5in;
}

p.documentation-title {
   font-weight: bold;
   border-bottom: 1pt solid gray;
}

div.schema-part-type-definition {
   width: 8in;
}

div.schema-part-element-decl {
   width: 8in;
}

div.schema-part-attribute-decl {
   width: 8in;
}

span.from-base-type {
   color: gray;
}

span.from-base-type a {
   color: gray;
}

span.schema-part-reqatt {
   font-weight: bold;
}

table.attributes {
   border-spacing: 0pt;
   width: 100%;
   margin-bottom: 15pt;
}

table.attributes td, table.attributes th {
   border: 1pt solid gray;
   padding: 5pt;
}

table.elements {
   border-spacing: 0pt;
   width: 100%;
   margin-bottom: 15pt;
}

table.elements td, table.elements th {
   border: 1pt solid gray;
   padding: 5pt;
}

p.issue {
   color: red;
}

.typename {
   font-weight: bold;
}

table.constraints {
   border-spacing: 0pt;
   width: 98%;
   margin-bottom: 15pt;
}

table.constraints td, table.constraints th {
   border: 1pt solid gray;
   padding: 5pt;
}

table.enumeration {
   border-spacing: 0pt;
   width: 98%;
   margin-bottom: 15pt;
}

table.enumeration td, table.enumeration th {
   border: 1pt solid gray;
   padding: 5pt;
}
   
</style>
</xsl:template>

<xsl:template name="script">
<script type="text/javascript" src="schema.js"><xsl:text> </xsl:text></script>
<xsl:result-document href="schema.js" method="text">
function DOM_text(node) {
   if (node.textContent) {
      return node.textContent;
   } else {
      return node.text;
   }
   return "";
}

function DOM_removeChildren(parent) {
   while (parent.childNodes.length>0) {
      parent.removeChild(parent.childNodes.item(0));
   }
}

function DOM_appendText(parent,text) {
   parent.appendChild(parent.ownerDocument.createTextNode(text));
}

var currentNamespace = null;
var namespaceList = new Array();

function setCurrentNamespace(ns) {
   currentNamespace = ns;
   var nsLabel = document.getElementById('current-ns');
   DOM_removeChildren(nsLabel);
   DOM_appendText(nsLabel,currentNamespace);
   for (var i=0; i&lt;namespaceList.length; i++) {
      var div = document.getElementById(namespaceList[i]);
      div.style.display = "none";
   }
   var div = document.getElementById(ns);
   div.style.display = "block";
}

function showContext(namespace) {
   setCurrentNamespace(namespace);
   showSelectedNamespace(namespace);
}

function showSelectedNamespace(namespace) {
   var nsList = document.getElementById('ns-list');
   var namespaces = nsList.getElementsByTagName('option');
   for (var i=0; i&lt;namespaces.length; i++) {
      var option = namespaces.item(i);
      if (option.getAttribute('value')==namespace) {
         option.selected = true;
      } else {
         option.selected = false;
      }
   }
}

function init() {
   var nsList = document.getElementById('ns-list');
   var namespaces = nsList.getElementsByTagName('option');
   for (var i=0; i&lt;namespaces.length; i++) {
      namespaceList[i] = namespaces.item(i).getAttribute('value');
      var div = document.getElementById(namespaceList[i]);
      div.style.display = "none";
   }
   setCurrentNamespace(nsList.getElementsByTagName('option').item(0).getAttribute('value'));
}
</xsl:result-document>
</xsl:template>


<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="$title"/></title>
<xsl:call-template name="generate-style"/>
<xsl:call-template name="script"/>
</head>
<body onload="init()">
<div id="ns-navigation">
   <form id="ns-select"><xsl:apply-templates mode="namespace_list"/></form>
   <p id="current-ns"></p>   
</div>
<div id="schema">
<xsl:apply-templates select="/ex:expanded-schema/ex:namespace" mode="enumerate-namespace"/>   
</div>
</body>

</html>
</xsl:template>

<xsl:template match="ex:expanded-schema" mode="namespace_list">
   <select id="ns-list" onchange="setCurrentNamespace(this.value)">
   <xsl:apply-templates select="ex:namespace" mode="namespace_list"/>
   </select>
</xsl:template>

<xsl:template match="ex:namespace" mode="namespace_list">
<option value="{@name}">
<xsl:choose>
  <xsl:when test="@name">
    <xsl:value-of select="@name"/>
  </xsl:when>
  <xsl:otherwise>
     (no namespace)
  </xsl:otherwise>
</xsl:choose>
</option>
</xsl:template>

<xsl:template match="ex:namespace" mode="enumerate-namespace">
<div class="namespace" id="{@name}">
   <div class="namespace-navigation">
   <xsl:apply-templates select="." mode="element_list"/>
   <xsl:apply-templates select="." mode="attribute_list"/>
   <xsl:apply-templates select="." mode="type_list"/>
   </div>

   <div class="contents">
   <xsl:if test="xs:element">
      <div class="elements">
         <h2>Elements</h2>
         <xsl:apply-templates select="xs:element" mode="individual">
            <xsl:sort select="@name"/>
         </xsl:apply-templates>
      </div>
   </xsl:if>
   <xsl:if test="xs:attribute">
      <div class="attributes">
         <h2>Attributes</h2>
         <xsl:apply-templates select="xs:attribute" mode="individual">
            <xsl:sort select="@name"/>
         </xsl:apply-templates>
      </div>
   </xsl:if>
   <xsl:if test="xs:complexType|xs:simpleType">
      <div class="types">
         <h2>Types</h2>
         <xsl:apply-templates select="xs:complexType|xs:simpleType" mode="individual">
            <xsl:sort select="@name"/>
         </xsl:apply-templates>
      </div>
   </xsl:if>
   </div>
</div>
<xsl:text>&#xa;</xsl:text>
</xsl:template>

<xsl:template match="ex:namespace"/>

<xsl:template match="xs:annotation" mode="namespace_list"/>


<xsl:template match="ex:namespace" mode="element_list">
<div id="elements">
   <h2>Elements</h2>
<xsl:choose>
  <xsl:when test="xs:element">
     <ul>
    <xsl:apply-templates select="xs:element" mode="element_list">
       <xsl:sort select="@name"/>
    </xsl:apply-templates>
     </ul>
  </xsl:when>
  <xsl:otherwise>
    <p>None</p>
  </xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>

<xsl:template name="element_link">
<a title="{{{../@name}}}{@name}">
<xsl:attribute name="href">#namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_element_<xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@name"/></a>
</xsl:template>

<xsl:template match="ex:namespace/xs:element" mode="element_list">
<li>
<p><xsl:call-template name="element_link"/></p>
</li>
</xsl:template>

<xsl:template match="xs:annotation" mode="element_list"/>



<xsl:template match="ex:namespace" mode="attribute_list">
<div id="attributes">
   <h2>Attributes</h2>
<xsl:choose>
  <xsl:when test="xs:attribute">
    <ul>
    <xsl:apply-templates select="ex:attribute" mode="attribute_list">
       <xsl:sort select="@name"/>
    </xsl:apply-templates>
    </ul>
  </xsl:when>
  <xsl:otherwise>
    <p>None</p>
  </xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>

<xsl:template name="attribute_link">
<a title="{{{../@name}}}{@name}">
<xsl:attribute name="href">#namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_attribute_<xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@name"/></a>
</xsl:template>

<xsl:template match="ex:namespace/xs:attribute" mode="attribute_list">
<li>
<p><xsl:call-template name="attribute_link"/></p>
</li>
</xsl:template>

<xsl:template match="xs:annotation" mode="attribute_list"/>


<xsl:template match="ex:namespace" mode="type_list">
   <div id="types">
      <h2>Types</h2>
<xsl:choose>
  <xsl:when test="xs:simpleType|xs:complexType">
     <ul>
       <xsl:apply-templates select="xs:simpleType|xs:complexType" mode="type_list">
          <xsl:sort select="@name"/>
       </xsl:apply-templates>
     </ul>
  </xsl:when>
  <xsl:otherwise>
    <p>None</p>
  </xsl:otherwise>
</xsl:choose>
   </div>
</xsl:template>

<xsl:template name="type_link">
<a title="{{{../@name}}}{@name}">
<xsl:attribute name="href">#namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_type_<xsl:value-of select="@name"/></xsl:attribute>
<xsl:value-of select="@name"/></a>
</xsl:template>

<xsl:template match="ex:namespace/xs:simpleType|ex:namespace/xs:complexType" mode="type_list">
<li>
<p><xsl:call-template name="type_link"/></p>
</li>
</xsl:template>

<xsl:template match="xs:annotation" mode="type_list"/>

<xsl:template match="ex:namespace/xs:annotation" mode="individual"/>

<xsl:template match="xs:element" mode="individual">
<xsl:variable name="href">namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_element_<xsl:value-of select="@name"/></xsl:variable>
<div class='element' id="{$href}">
   <h3><xsl:value-of select="@name"/></h3>   
   <xsl:call-template name="schema-element-decl"/>
   <xsl:call-template name="schema-documentation"/>
</div>
</xsl:template>

<xsl:template match="xs:attribute" mode="individual">
<xsl:variable name="href">namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_attribute_<xsl:value-of select="@name"/></xsl:variable>
<div class='attribute' id="{$href}">
   <h3><xsl:value-of select="@name"/></h3>
   <xsl:call-template name="schema-attribute-decl"/>
   <xsl:call-template name="schema-documentation"/>
</div>
</xsl:template>

<xsl:template match="xs:simpleType" mode="individual">
<xsl:variable name="href">namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_type_<xsl:value-of select="@name"/></xsl:variable>
<div class='type' id="{$href}">
   <h3><xsl:value-of select="@name"/></h3>
   <xsl:call-template name="schema-simple-type-definition"/>
   <xsl:call-template name="schema-documentation"/>
</div>
</xsl:template>

<xsl:template match="xs:complexType" mode="individual">
<xsl:variable name="href">namespace_<xsl:number count="ex:namespace" level="single" format="1"/>_type_<xsl:value-of select="@name"/></xsl:variable>
<div class='type' id="{$href}">
   <h3><xsl:value-of select="@name"/></h3>
   <xsl:call-template name="schema-complex-type-definition"/>
   <xsl:call-template name="schema-documentation"/>
</div>
</xsl:template>

<xsl:template match="h:*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*"><xsl:copy/></xsl:template>

<xsl:template name="ref">
<xsl:param name="prefix"/>
<xsl:param name="namespace"/>
<xsl:param name="name"/>
<xsl:param name="type"/>
<a class='typename'>
<xsl:if test='$namespace!="http://www.w3.org/2001/XMLSchema"'>
<xsl:attribute name="href">
<xsl:text>#namespace_</xsl:text>
<xsl:choose>
   <xsl:when test="$namespace">
      <xsl:for-each select="/ex:expanded-schema/ex:namespace[@name=$namespace]">
         <xsl:number count="ex:namespace" level="single" format="1"/>
      </xsl:for-each>
   </xsl:when>
   <xsl:otherwise>
      <xsl:for-each select="/ex:expanded-schema/ex:namespace[not(@name)]">
         <xsl:number count="ex:namespace" level="single" format="1"/>
      </xsl:for-each>
   </xsl:otherwise>
</xsl:choose>
<xsl:text>_</xsl:text>
<xsl:value-of select="$type"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="$name"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$namespace">
<xsl:attribute name="onclick">showContext('<xsl:value-of select="$namespace"/>')</xsl:attribute>
</xsl:if>
<xsl:value-of select="$prefix"/>
<xsl:value-of select="$name"/>
</a>
</xsl:template>

</xsl:stylesheet>
